//
//  TestBasedViewController.m
//  YTT-IOS-CommonFramework
//
//  Created by aron on 2017/2/23.
//  Copyright © 2017年 aron. All rights reserved.
//

#import "TestBasedViewController.h"
#import "ActionCellModel.h"

@interface TestBasedViewController ()

@property (nonatomic, strong) NSMutableArray* actionCellModels;

@end

@implementation TestBasedViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.actionCellModels = [NSMutableArray new];
 
    [self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:NSStringFromClass(UITableViewCell.class)];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - ......::::::: public :::::::......

- (void)addActionWithName:(NSString*)actionName callback:(void(^)())callback {
    ActionCellModel* model = [[ActionCellModel alloc] initWithActionName:actionName actionCallBack:^{
        callback();
    }];
    [_actionCellModels addObject:model];
}

#pragma mark - Table view data source

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return _actionCellModels.count;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell* cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass(UITableViewCell.class)];
    ActionCellModel* model = _actionCellModels[indexPath.row];
    cell.textLabel.text = model.actionName;
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    ActionCellModel* model = _actionCellModels[indexPath.row];
    model.actionCallBack();
}

@end
